{include file="public/header" /}
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>优惠券</h3>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>

    <form id="goods_class_form" method="post"
          action="{if isset($t_info)}{:url('Voucher/priceedit')}{else/}{:url('Voucher/priceadd')}{/if}">
        <table class="ds-default-table">
            <tbody>
            <td colspan="2" class="required" style="height: 74px;"><label class="validation">优惠券名称:</label>
                <input style="margin-left: 60px;" type="text" value="{$t_info.voucher_title|default=''}" name="title"
                       id="title" maxlength="20" class="txt">
                <p style=" margin-left: 312px;
    margin-top: -24px;"> &nbsp;</p>
            </td>
            
<!--
{if empty($t_info.b_names)}
            <tr>
                    <td id="hide_brands" colspan="2"><label class="validation">商品品牌:</label>
                        <div  style='margin-left: 147px;' id="ajax_brand" class="dssc-brand-select w180">
                            <div class="selection">
                            <input style="margin-top:-16px;"  name="b_name" id="b_name" value="{$Request.param.b_name|default=''}" type="text"
                                   class="txt w180" readonly="readonly"/>
                            <input type="hidden" name="b_id" id="b_id" value="{$Request.param.b_id|default=''}"/>
                        </div>
                            <div style="margin-top: -11px;" class="dssc-brand-select-container">
                                <div class="brand-index" style="width: 210px;padding-bottom: 10px;margin: 6px auto;border-bottom: dotted 1px #CCC;" data-url="{:url('Common/ajax_get_brand')}">
                                    <div class="letter" dstype="letter">
                                        <ul style="width: 100%;" >
                                            <li style="width: auto;" ><a href="javascript:void(0);" data-letter="all">所有品牌</a></li>
                                            <li style="width: auto;" ><a href="javascript:void(0);" data-letter="A">A</a></li>
                                            <li style="width: auto;" ><a href="javascript:void(0);" data-letter="B">B</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="C">C</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="D">D</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="E">E</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="F">F</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="G">G</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="H">H</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="I">I</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="J">J</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="K">K</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="L">L</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="M">M</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="N">N</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="O">O</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="P">P</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="Q">Q</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="R">R</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="S">S</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="T">T</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="U">U</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="V">V</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="W">W</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="X">X</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="Y">Y</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="Z">Z</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="0-9">其他</a></li>
                                        </ul>
                                    </div>
                                    <div class="search" dstype="search"><input name="search_brand_keyword" id="search_brand_keyword" type="text" class="text" /><a href="javascript:void(0);" class="dssc-btn-mini" style="vertical-align: top;">Go</a></div>
                                </div>
                                <div class="brand-list" dstype="brandList">
                                    <ul  dstype="brand_list">
                                        {notempty name="brand_list"}
                                        {foreach name="brand_list" item="val"}
                                        <li style="width: 200px;" data-id='{$val.brand_id}'data-name='{$val.brand_name}'>

                                        <input type="hidden" name="b_names" data-names='{$val.brand_name}'  value="{$val.brand_name}">

                                        <input type="checkbox" name="b_ids" data-id='{$val.brand_id}'  value="{$val.brand_id}" >{$val.brand_name}</li>
                                        {/foreach}
                                        {/notempty}
                                    </ul>
                                </div>
                                <div class="no-result" dstype="noBrandList" style="display: none;">暂无品牌信息</div>
                            </div>
                        </div>
                    </td>
            </tr>
            {else if/}
            <tr>
                    <td id="hide_brands" colspan="2" style="display: none;"><label class="validation">商品品牌:</label>
                        <div  style='margin-left: 147px;' id="ajax_brand" class="dssc-brand-select w180">
                            <div class="selection">
                            <input style="margin-top:-16px;"  name="b_name" id="b_name" value="{$Request.param.b_name|default=''}" type="text"
                                   class="txt w180" readonly="readonly"/>
                            <input type="hidden" name="b_id" id="b_id" value="{$Request.param.b_id|default=''}"/>
                        </div>
                            <div style="margin-top: -11px;" class="dssc-brand-select-container">
                                <div class="brand-index" style="width: 210px;padding-bottom: 10px;margin: 6px auto;border-bottom: dotted 1px #CCC;" data-url="{:url('Common/ajax_get_brand')}">
                                    <div class="letter" dstype="letter">
                                        <ul style="width: 100%;" >
                                            <li style="width: auto;" ><a href="javascript:void(0);" data-letter="all">所有品牌</a></li>
                                            <li style="width: auto;" ><a href="javascript:void(0);" data-letter="A">A</a></li>
                                            <li style="width: auto;" ><a href="javascript:void(0);" data-letter="B">B</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="C">C</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="D">D</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="E">E</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="F">F</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="G">G</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="H">H</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="I">I</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="J">J</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="K">K</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="L">L</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="M">M</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="N">N</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="O">O</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="P">P</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="Q">Q</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="R">R</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="S">S</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="T">T</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="U">U</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="V">V</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="W">W</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="X">X</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="Y">Y</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="Z">Z</a></li>
                                            <li style="width: auto;"><a href="javascript:void(0);" data-letter="0-9">其他</a></li>
                                        </ul>
                                    </div>
                                    <div class="search" dstype="search"><input name="search_brand_keyword" id="search_brand_keyword" type="text" class="text" /><a href="javascript:void(0);" class="dssc-btn-mini" style="vertical-align: top;">Go</a></div>
                                </div>
                                <div class="brand-list" dstype="brandList">
                                    <ul  dstype="brand_list">
                                        {notempty name="brand_list"}
                                        {foreach name="brand_list" item="val"}
                                        <li style="width: 200px;" data-id='{$val.brand_id}'data-name='{$val.brand_name}'>

                                        <input type="hidden" name="b_names" data-names='{$val.brand_name}'  value="{$val.brand_name}">

                                        <input type="checkbox" name="b_ids" data-id='{$val.brand_id}'  value="{$val.brand_id}" >{$val.brand_name}</li>
                                        {/foreach}
                                        {/notempty}
                                    </ul>
                                </div>
                                <div class="no-result" dstype="noBrandList" style="display: none;">暂无品牌信息</div>
                            </div>
                        </div>
                    </td>
                    
                    <td id="show_brands" colspan="2" class="required" style="height: 74px;"><label class="validation">品牌名称:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        {$t_info.b_names}
                        <input type="button" value="编辑" id="gc_edit">
                        <input name="gc_ids" value="1"  type="hidden" id="gc_ids">
                        <p style="margin-left: 312px;margin-top: -5px;"> &nbsp;</p>
                    </td>
                
            </tr>

            {/if}
            
-->



            <tr class="noborder">
                <td colspan="2" class="required"><label class="validation">优惠券类型:</label>
                    <select name="vou_type" style="margin-left: 59px;" id="vou_type">
                        <option value="1"
                        <?php if(isset($t_info) && $t_info['vou_type']==1){?>selected="selected"<?php }?>
                        >商城</option>
                        <option value="2"
                        <?php if(isset($t_info) && $t_info['vou_type']==2){?>selected="selected"<?php }?>
                        >服务</option>
                        <option value="3"
                        <?php if(isset($t_info) && $t_info['vou_type']==3){?>selected="selected"<?php }?>
                        >项目</option>
                    </select></td>
            </tr>
            <tr class="noborder" id="type_content">
                <td colspan="2" class="required" id="gc_info"><label class="validation">商品分类:</label>
                    <?php if(isset($t_info)){ ?>
                    <?php if(isset($t_info)&&$t_info['vou_type']==1){ ?>
                    <span style="margin-left: 100px;"  id="gc_span">{$t_info.vou_gcname|default=''} <input type="button" id="edit_gcname" value="编辑">
                    <input type="hidden" name="edit_class_id" value="{$t_info.vou_gcid|default=''}"></span>
                    <input type="hidden" name="edit_class_name" value="{$t_info.vou_gcname|default=''}"></span>
                    <div id="gcategory" style="margin-left: 134px;margin-top:-20px;display:none;">
                        <input type="hidden" name="class_id" value="0" class="mls_id"/>
                        <input type="hidden" name="class_name" value="通用"
                               class="mls_name"/>
                        {if $type.class_id}
                        <span>{$type.class_name|default=''}</span>
                        <input type="button" value="{$Think.lang.ds_edit}" class="edit_gcategory"/>
                        {/if}
                        <select style="margin-left: 12px;" {if $type.class_id}style="display:none" {/if}>
                        <option value="0">请选择</option>
                        {foreach name="gc_list" item="gc"}
                        <option value="{$gc.gc_id}">{$gc.gc_name}</option>
                        {/foreach}
                        </select>
                    </div>
                    <?php }else{ ?>
                    <div id="gcategory" style="margin-left: 134px;margin-top:-20px;">
                        <input type="hidden" name="class_id" value="0" class="mls_id"/>
                        <input type="hidden" name="class_name" value="通用"
                               class="mls_name"/>
                        {if $type.class_id}
                        <span>{$type.class_name|default=''}</span>
                        <input type="button" value="{$Think.lang.ds_edit}" class="edit_gcategory"/>
                        {/if}
                        <select style="margin-left: 12px;" {if $type.class_id}style="display:none" {/if}>
                        <option value="0">请选择</option>
                        {foreach name="gc_list" item="gc"}
                        <option value="{$gc.gc_id}">{$gc.gc_name}</option>
                        {/foreach}
                        </select>
                    </div>
                    <?php }?>
                    <?php }else{ ?>
                    <div id="gcategory" style="margin-left: 134px;margin-top:-20px; ">
                        <input type="hidden" name="class_id" value="0" class="mls_id"/>
                        <input type="hidden" name="class_name" value="通用"
                               class="mls_name"/>
                        {if $type.class_id}
                        <span>{$type.class_name|default=''}</span>
                        <input type="button" value="{$Think.lang.ds_edit}" class="edit_gcategory"/>
                        {/if}
                        <select style="margin-left: 12px;" {if $type.class_id}style="display:none" {/if}>
                        <option value="0">请选择</option>
                        {foreach name="gc_list" item="gc"}
                        <option value="{$gc.gc_id}">{$gc.gc_name}</option>
                        {/foreach}
                        </select>
                    </div>
                    <?php } ?>

                </td>

                <td colspan="2" class="required" id="service_info"><label class="validation">服务:</label>
                    <div style="margin-left: 134px;margin-top:-20px; ">
                        <select style="margin-left: 12px;" name="vou_type_content">
                            <option value="1"
                            <?php if(isset($t_info) && $t_info['vou_type']==2 && $t_info['vou_gcid']==1){?>
                            selected="selected"<?php }?>
                            >保养</option>
                            <option value="2"
                            <?php if(isset($t_info) && $t_info['vou_type']==2 && $t_info['vou_gcid']==2){?>
                            selected="selected"<?php }?>
                            >维修</option>
                            <option value="3"
                            <?php if(isset($t_info) && $t_info['vou_type']==2 && $t_info['vou_gcid']==3){?>
                            selected="selected"<?php }?>
                            >安装</option>
                            <option value="4"
                            <?php if(isset($t_info) && $t_info['vou_type']==2 && $t_info['vou_gcid']==4){?>
                            selected="selected"<?php }?>
                            >拆移</option>
                        </select>
                    </div>
                </td>

            </tr>

            <tr class="noborder">
                <td colspan="2" class="required" style="height:50px; "><label class="validation">金额:</label>
                    <div>
                        <!--<p style="margin-left: 154px;margin-top:-18px; ">优惠券金额：</p>-->
                        <input style="margin-left: 145px;margin-top:-23px;" placeholder="优惠券金额" type="text" name="voucher_price"class="txt" value="{$t_info.voucher_price|default=''}">
                        <input style="margin-left: 2px;margin-top:-23px;" placeholder="满多少可用" type="text" name="voucher_limit" class="txt" value="{$t_info.voucher_limit|default=''}">

                        <!--<p style="margin-left: 312px;margin-top:-36px;font-size:14px;height:28px; "></p>-->
                    </div>
                    <div>
                        <!--<p style="margin-left: 818px;margin-top:-18px; ">满多少可用：</p>-->
                      <!--<p style="margin-left: 779px;margin-top:-36px;font-size:14px;height:28px;"></p>-->
                    </div>
                </td>
            </tr>

            <tr class="noborder">
                <td colspan="2" class="required" style="height:50px; "><label class="validation">时间设置:</label>
                    <div>
                        <input style="margin-left: 145px;margin-top:-24px;width:100px;" placeholder="开始时间" type="text" id="sdate" name="voucher_startdate" class="txt date" readonly="readonly"  value="<?php if(isset($t_info)){ echo date('Y-m-d',$t_info['voucher_startdate']); }?>">
                        <input style="margin-top:-24px;width:100px;" placeholder="结束时间" type="text" id="edate"name="voucher_enddate" class="txt date"  readonly="readonly"    value="<?php if(isset($t_info)){ echo date('Y-m-d',$t_info['voucher_enddate']); } ?>">
                        <input style="margin-left:5px;margin-top:-24px;width: 100px;" placeholder="有效天数" type="text" class="txt" name="use_date" value="{$t_info.use_date|default=''}">
                    </div>
                </td>

            </tr>
            
            <tr class="noborder">
            <td colspan="2" class="required" style="height: 74px;"><label class="validation">供应商分担比例：</label>
               <input style="margin-left: 22px;" type="text" name="g_ratio" id="g_ratio"class="txt" value="{$t_info.g_ratio|default=''}">
                <p style=" margin-left: 312px;margin-top: -24px;"> %&nbsp;</p>
            </td>
            </tr>
            <tr class="noborder">
            <td colspan="2" class="required" style="height: 74px;"><label class="validation">商城分担比例：</label>
               <input style="margin-left: 34px;" type="text" name="y_ratio" id="y_ratio"
                               class="txt" value="{$t_info.z_ratio|default=''}">
                <p style=" margin-left: 312px;margin-top: -24px;"> %&nbsp;</p>
            </td>
            </tr>
            
            <tr class="noborder">
            <td colspan="2" class="required" style="height: 74px;"><label class="validation">运营商分担比例：</label>
               <input style="margin-left: 22px;" type="text" name="z_ratio" id="z_ratio"
                               class="txt" value="{$t_info.y_ratio|default=''}">
                <p style=" margin-left: 312px;margin-top: -24px;"> %&nbsp;</p>
            </td>
            </tr>

            <tr class="noborder">
                <td colspan="2" class="required" style="height: 74px;"><label class="validation">发行数量：</label>
                    <input style="margin-left: 22px;" type="text" name="count" id="count"
                           class="txt" value="{$t_info.count|default=''}">
                    <p style=" margin-left: 312px;margin-top: -24px;"> 发行数量&nbsp;</p>
                </td>
            </tr>

            <tr class="noborder">
                <td colspan="2" class="required" style="height: 74px;"><label class="validation">多少积分可换：</label>
                    <input style="margin-left: 22px;" type="text" name="score_count" id="score_count"
                           class="txt" value="{$t_info.score_count|default=''}">
                    <p style=" margin-left: 312px;margin-top: -24px;"> 多少积分可得兑换优惠券&nbsp;</p>
                </td>
            </tr>

            
            <tr class="noborder">
                <td class="vatop rowform" style="height: 30px;">
                    <label class="validation">是否启用：</label>
                    <div class="onoff" style="margin-top: -18px;
margin-left: 133px;">
                        <label for="site_state1"
                               class="cb-enable <?php if(isset($t_info) && $t_info['status']==1){?> selected <?php }else if(!isset($t_info)){echo 'selected';}?>">{$Think.lang.ds_open}</label>
                        <label for="site_state0"
                               class="cb-disable <?php if(isset($t_info) && $t_info['status']==0){?> selected <?php }?>">{$Think.lang.ds_close}</label>
                        <input id="site_state1" name="status" value="1"
                               type="radio" <?php if(isset($t_info) && $t_info['status']==1){?>
                        checked="checked"<?php }else if(!isset($t_info)){?> checked="checked" <?php }?>  >
                        <input id="site_state0" name="status" value="0"
                               type="radio" <?php if(isset($t_info) && $t_info['status']==0){?>
                        checked="checked"<?php }?>  >
                    </div>
                </td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="2">
                    <?php if(isset($t_info)){?>
                    <input type="hidden" name="id" value="{$t_info.voucher_id}">
                    <?php }?>
                    <input class="btn" type="submit"  style='line-height: 30px;' value="{$Think.lang.ds_submit}"/></td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>
<link rel="stylesheet" href="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.css">
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/jquery-ui-timepicker-addon.min.js"></script>
<script src="{$Think.PLUGINS_SITE_ROOT}/js/jquery-ui-timepicker/i18n/jquery-ui-timepicker-zh-CN.js"></script>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js" charset="utf-8"></script>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/jquery.mousewheel.js"></script> 
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js" charset="utf-8"></script>
<script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/jquery.mousewheel.js"></script>
<script>

    $('#edit_gcname').click(function(){
        $('#gc_span').remove();
        $("#gcategory").show();
    });
    $('#gc_edit').click(function () {
        $('#show_brands').hide();
        $('#hide_brands').show();
    });

    $(function () {
        //   $("#service_info").hide();
        //选择日期
        $('#sdate').datepicker({dateFormat: 'yy-mm-dd'});
        $('#edate').datepicker({dateFormat: 'yy-mm-dd'});

        $('#vou_type').change(function () {
            var type = $(this).val();
            if (type == 1) {
                //商城
                $('#gc_info').show();
                $("#service_info").hide();
            } else if (type == 2) {
                $("#gc_info").hide();
                //服务
                $("#service_info").show();
            } else {
                $('#gc_info').hide();
                $("#service_info").hide();
            }
        });

        $('#type_div').perfectScrollbar();
        $("#pic").change(function () {
            $("#textfield1").val($(this).val());
        });
        $('input[type="radio"][name="cat_id"]').click(function () {
            if ($(this).val() == '0') {
                $('#t_name').val('');
            } else {
                $('#t_name').val($(this).next('span').html());
            }
        });
        // 所属分类
        $(document).off('change', "#gc_parent_id").on("change", "#gc_parent_id", function () {
            type_scroll($(this));
        });
        // 类型搜索
        $(document).off('change', "#gcategory > select").on("change", "#gcategory > select", function () {
            type_scroll($(this));
        });


        jQuery.validator.addMethod("checkFCodePrefix", function (value, element) {
            return this.optional(element) || /^[a-zA-Z]+$/.test(value);
        }, '<i class="iconfont">&#xe64c;</i>{$Think.lang.prompt_information1}');


        $('#goods_class_form').validate({
            errorPlacement: function (error, element) {
                $(element).nextAll('p').append(error);
            },
            rules: {
                title: {
                    required: true,
                },
                voucher_price: {
                    required: true,
                    number: true,
                    min: 0.01,
                },
                voucher_startdate: {
                    required: true,
                },
                voucher_enddate: {
                    required: true,
                },
                use_date: {
                    required: true,
                    digits: true,
                    min: 1
                },
                voucher_limit: {
                    required: true,
                    number: true,
                    min: 0.01,
                },
                g_ratio: {
                    required: true,
                    number: true,
                    min: 0,
                },
                y_ratio: {
                    required: true,
                    number: true,
                    min: 0,
                },
                z_ratio: {
                    required: true,
                    number: true,
                    min: 0,
                },
                count: {
                    required: true,
                    number: true,
                    min: 1,
                },
                score_count: {
                    required: true,
                    number: true,
                    min: 0,
                },
            },
            messages: {
                title: {
                    required: '不能为空'
                },
                voucher_startdate: {
                    required: '不能为空'
                },
                voucher_enddate: {
                    required: '不能为空'
                },
                use_date: {
                    required: '不能为空',
                    digits: '请设置整数',
                    min: '请设置大于或者等于1的整数',
                },
                voucher_price: {
                    required: '不能为空',
                    number: '请设置正确的数值',
                    min: '请设置正确的数值',
                },
                g_ratio: {
                    required: '不能为空',
                    number: '请设置正确的数值',
                    min: '请设置正确的数值',
                },
                y_ratio: {
                    required: '不能为空',
                    number: '请设置正确的数值',
                    min: '请设置正确的数值',
                },
                z_ratio: {
                    required: '不能为空',
                    number: '请设置正确的数值',
                    min: '请设置正确的数值',
                },
                voucher_limit: {
                    required: '不能为空',
                    number: '请设置正确的数值',
                    min: '请设置正确的数值',
                },
                count: {
                    required: '不能为空',
                    number: '请设置正确的数值',
                    min: '请设置正确的数值',
                },
                score_count: {
                    required: '不能为空',
                    number: '请设置正确的数值',
                    min: '请设置正确的数值',
                },
            }
        });

        $("form").submit(function (e) {
            var res = $("#goods_class_form").valid();
            if (res) {
                var url = $('form').attr('action');

                var voucher_enddate = $("input[name='voucher_enddate']").val();

                var voucher_startdate = $("input[name='voucher_startdate']").val();
                var enddate = (new Date(voucher_enddate)).getTime() / 1000;
                var startdate = (new Date(voucher_startdate)).getTime() / 1000;
                var today = new Date();

                var dates = new Date(today.getFullYear(), today.getMonth(), today.getDate(), 8, 0, 0).getTime() / 1000;


                if (enddate < dates) {
                    layer.msg('优惠券结束时间不能小于今天');
                    return false;
                }

                if (startdate > enddate) {
                    layer.msg('优惠券结束时间不能小于开始时间');
                    return false;
                }

                var g_ratio = Number($('#g_ratio').val());
                var z_ratio = Number($('#z_ratio').val());
                var y_ratio = Number($('#y_ratio').val());

                 var sum = g_ratio+z_ratio+y_ratio;
                 if(sum!=100){
                     layer.msg('分担比例不对,请重新设置');
                     return false;
                 }

                $.ajax({
                    type: "POST",
                    url: url,
                    data: $('#goods_class_form').serialize(),// 你的formid
                    error: function (request) {
                        alert("Connection error");
                    },
                    success: function (result) {
                    //    alert(result) ;return false;
                        if (result.code == 0) {
                            layer.msg(result.msg);
                            location.href = result.url;
                            return false;
                        } else {
                            layer.msg(result.msg);
                            location.href = result.url;
                            return false;

                        }
                    }
                });
                return false;
            }

        });

    });

    var typeScroll = 0;

    function type_scroll(o) {
        var id = o.val();
        if (!$('#type_dt_' + id).is('dt')) {
            return false;
        }
        $('#type_div').scrollTop(-typeScroll);
        var sp_top = $('#type_dt_' + id).offset().top;
        var div_top = $('#type_div').offset().top;
        $('#type_div').scrollTop(sp_top - div_top);
        typeScroll = sp_top - div_top;
    }
    //按钮先执行验证再提交表单
    $(document).ready(function () {
        var type = $('#vou_type').val();
        if (type == 1) {
            //商城
            $('#gc_info').show();
            $("#service_info").hide();
        } else if (type == 2) {
            $("#gc_info").hide();
            //服务
            $("#service_info").show();
        } else {
            $('#gc_info').hide();
            $("#service_info").hide();
        }
            /* AJAX选择品牌 */
        $("#ajax_brand").brandinit();

        $('#dssubmit').click(function(){
            $('#formSearch').submit();
        });
        $('#company_address').ds_region();
    });
    gcategoryInit('gcategory');
</script>


